import json

import requests

from info_auto.common.logger import logger


class RequestUtil:
    session = requests.session()

    def send_request(self, method, url, data, **kwargs):
        method = str(method).lower()
        if method == 'get':
            res = RequestUtil.session.request(method, url=url, params=data, **kwargs)
        elif method == 'post':
            data = json.dumps(data)
            res = RequestUtil.session.request(method, url=url, data=data, **kwargs)
        else:
            pass
        logger.debug(f"发送请求:{res.text}")
        return res.text